﻿/* Copyright (C) Siemens AG, 2012. All Rights Reserved.
 * Author: Roland Eckl, Corporate Technology
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System.Collections;
using System.ServiceModel;


namespace RVM.Infrastructure.Communication
{
    /// <summary>
    /// Interface for ViewModelAgents. These are the actual agents responsible for the communication over
    /// some technology/protocol.
    /// </summary>
    [ServiceContract(SessionMode=SessionMode.Required, CallbackContract=typeof(IViewModelCallback))]
    public interface IViewModelAgent
    {
        /// <summary>
        /// Ask for specific remote view models
        /// </summary>
        /// <param name="id">Unique ID of queried ViewModel</param>
        /// <returns></returns>
        [OperationContract]
        bool Has(string id);

        /// <summary>
        /// Registers an agent at an exported remote ViewModel.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        bool Register(string id);

        /// <summary>
        /// Removes an agent from an exported remote ViewModel.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        bool Unregister(string id);

        /// <summary>
        /// Fires PropertyChanged event through callback channel.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="property"></param>
        [OperationContract]
        void FirePropertyChanged(string id, string property);

        /// <summary>
        /// Fires CollectionChanged event through callback channel.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="property"></param>
        /// <param name="details">Details on performed action</param>
        [OperationContract]
        void FireCollectionChanged(string id, string property, CollectionChangedEventArgs details);
      
        /// <summary>
        /// Sets the value for a property on the exported viewmodel.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="property"></param>
        /// <param name="value"></param>
        /// <param name="supressNotification"></param>
        [OperationContract]
        void SetValue(string id, string property, object value, bool supressNotification);

        /// <summary>
        /// Gets a property's value for an exported viewmodel.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="property"></param>
        /// <param name="defaultvalue"></param>
        /// <returns></returns>
        [OperationContract]
        object GetValue(string id, string property, object defaultvalue);

        /// <summary>
        /// Gets a collections's content for an exported viewmodel.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="property"></param>
        /// <returns></returns>
        [OperationContract]
        IList GetCollection(string id, string property);

        /// <summary>
        /// Executes a command on an exported viewmodel.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="command"></param>
        /// <param name="parameter"></param>
        [OperationContract]
        void ExecuteCommand(string id, string command, object parameter);

        /// <summary>
        /// Checks the predicate for a command on an exported viewmodel.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="command"></param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        [OperationContract]
        bool CanExecuteCommand(string id, string command, object parameter);
    }
}
